import { depositList , depositPayment} from '../../../../api/deposit'


const util = require('../../../../utils/util.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageNum: 1,
        pageSize: 10,
        detailedList: [],
        currentTab: 0,
    },
    helpRecharge(e){
        var _this = this
        wx.showModal({
            title: '确定支付',
            // content: '确定代充',
            success (res) {
                if (res.confirm) {
                    let params = {}
                    params.depositId = e.currentTarget.dataset.id
                    depositPayment(params).then(res=>{
                        wx.showToast({
                            title: "支付成功",
                            icon: 'none',
                            duration: 2000,
                            success:function(){
                                _this.refresh()
                            }
                        })
                    }).catch(error=>{
                        wx.showToast({
                            title: error.content,
                            icon: 'none',
                            duration: 2000,
                        })
                    })
                } else if (res.cancel) {
                }
            }
        })

    },
    onPullDownRefresh() {
        wx.showNavigationBarLoading()
        this.data.pageNum = 1
        setTimeout(() => {
            wx.hideNavigationBarLoading()
            this.loadPoint()
            wx.stopPullDownRefresh()
        }, 1000);
    },

    onReachBottom() {
        this.data.pageNum += 1
        this.loadPoint()
    },

    formatDate2Time(val) {
        let date = new Date(val);
        let y = date.getFullYear();
        let MM = date.getMonth() + 1;
        MM = MM < 10 ? ('0' + MM) : MM;
        let d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        let h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        let m = date.getMinutes();
        m = m < 10 ? ('0' + m) : m;
        let s = date.getSeconds();
        s = s < 10 ? ('0' + s) : s;
        return y + '-' + MM + '-' + d + " " + h + ":" + m + ":" + s;
    },
    loadPoint() {
        if (this.data.pageNum == 1) {
            this.data.detailedList = []
        }
        if (this.data.currentTab == 1) {
            this.data.currentTab = 2
        }

        let params ={}
        params.pageSize =this.data.pageSize,
            params.pageNum = this.data.pageNum,
            params.status =this.data.currentTab
        if(this.data.currentTab == 1){
            params.status = 2
        }
        depositList(params).then(res => {
            res.data.data.forEach(item => {
                item.createDate = this.formatDate2Time(item.createDate)
                item.thumbnail = 'http://cdn.rzico.com/v4.0/wallet-consumption.png'
                this.data.detailedList.push(item)
            })
            this.setData({
                detailedList: this.data.detailedList
            })
            console.log( this.data.detailedList,"123123")
        })
    },
    //  tab切换逻辑
    swichNav: function (e) {
        this.data.pageNum=1
        this.data.detailedList=[]
        console.log(e)
        var that = this;
        if (this.data.currentTab === e.currentTarget.dataset.current) {
            return false;
        } else {
            that.setData({
                // status:e.currentTarget.dataset.current,
                currentTab: e.currentTarget.dataset.current
            })

            this.loadPoint()
        }
    },

    onLoad: function (options) {
        this.loadPoint()
    },
    refresh(){
        this.data.pageNum=1
        this.data.detailedList=[]
        this.loadPoint()
    },

})
